//线上域名
var domain_url = '';

//微信jsapi
var wxJsApi = ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'openLocation'];

//获取地址栏参数
function getParameterByName(name) {
	name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
	var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
		results = regex.exec(location.search);
	return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

//根据属性值从json数组中检索对象
function findElement(arr, propName, propValue) {
	for (var i = 0; i < arr.length; i++)
		if (arr[i][propName] == propValue)
			return arr[i];
}

//JSON String to base64
function jsonObjToBase64(json) {
	return btoa(encodeURIComponent(JSON.stringify(json)));
}
//base64 to JSON String
function base64TojsonObj(base64) {
	return eval('(' + decodeURIComponent(atob(base64)) + ')');
}

function asteriskPhoneNum(phonenum) {
	str1 = phonenum.substr(0, 3);
	str2 = phonenum.substr(3, 4);
	str3 = phonenum.substr(7, 4);
	phonenum = str1 + "****" + str3;
	return phonenum;
}

//JSON to URL
function jsonToUrl(json) {
	return '?' + Object.keys(json).map(function(key) {
		return encodeURIComponent(key) + '=' + encodeURIComponent(json[key]);
	}).join('&');
}

//验证数字输入
function validNum(event) {
	return (event.charCode >= 48 && event.charCode <= 57) || event.charCode == 46;
}
//重写window.alert
// window.alert = function(msg){
// 	alert(msg);
// }

//cookie操作
function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	} else
		var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}
/**
 * 自动登录
 **/
function autoLogin() {
	var localUserInfo = readCookie('CheerhiUserInfo');
	if (localUserInfo != null) {
		var userInfo = base64TojsonObj(localUserInfo);
		var urlLogin = server_host + '/web/user/login.do';
		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: urlLogin + '?phoneNum=' + userInfo.userName + '&passwd=' + userInfo.password,
			success: function(data) {
				// sessionStorage.setItem('userPhone',data.phone);
				// console.log(data);
			}
		});
	}
}

// 统计
var _maq = _maq || [];
_maq.push(['_setMaq', 'viewport']);
_maq.push(['_setType','weixin']);
var ma = document.createElement('script'); ma.type = 'text/javascript'; ma.async = true;
ma.src = ('http:' == document.location.protocol ? 'http://www.cheerhi.com' : 'https://www.cheerhi.com') + '/js/vis1.0.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ma, s);

